
import Vuex from 'vuex'

let locationData = {}
try{
	locationData = uni.getStorageSync('location')
}catch(e){
	console.log(e)
}

const states = {
	vuex_cityCode: locationData.vuex_cityCode ? locationData.vuex_cityCode : '1100',
	vuex_areaId: locationData.vuex_areaId ? locationData.vuex_areaId : '',
	vuex_city: locationData.vuex_city ? locationData.vuex_city : '北京',
	vuex_latelyCity: locationData.latelyCity ? locationData.latelyCity: ["深圳", "北京", "惠州"],
	vuex_location: locationData.location ? locationData.location : {}
}

const actions = {
  /**
   * 获取当前定位的经纬度
   */
  locationLogLat({ commit }) {
    return new Promise((resolve, reject) => {
      //#ifdef H5
      const geolocation = new BMap.Geolocation();
      geolocation.getCurrentPosition(function (r) {
        resolve({longitude: r.point.lng, latitude: r.point.lat})
      },{enableHighAccuracy: true})
	  //#endif
	  
      //#ifdef MP-WEIXIN
      uni.getLocation({
        type: "wgs84",
        success: async (res) => {
            resolve(res)
        },
      });
      //#endif
    })
  }
}

export default {
	namespaced: true,
	states,
    actions,
}